package com.xbongbong.pro.message.pushset;/*/*/

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.message.base.AbstractPushSet;
import com.xbongbong.pro.message.constant.PushSetConstant;
import com.xbongbong.pro.message.enums.PushTimeTypeEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.model.PushSetModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class PayPlanRemindOverduePushSet extends AbstractPushSet{

    private static  Integer oneDay = 86400;

    @Override
    public PushSetEntity toPushSetEntity(String pushObject, String pushTime, String attrEntity) {
        return null;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, Integer subType, PushSetModel pushSetModel) {
        Integer type = PushTypeEnum.PAY_PLAN_OVERDUE.getCode();

        Map<String,Object> param = new HashMap<>(16);
        param.put("corpid", corpid);
        param.put("type", type);
        param.put("subType", subType);
        List<PushSetEntity> pushSetList = pushSetModel.findEntitys(param);

        PushSetEntity pushSetEntity;
        if(pushSetList.isEmpty()){
            pushSetEntity = new PushSetEntity();
            pushSetEntity.setType(type);
            pushSetEntity.setSubType(subType);
            pushSetEntity.setEnable(0);
            JSONObject pushObject = new JSONObject();
            if (Objects.equals(PushTypeEnum.PAY_PLAN_OVERDUE.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.PAY_PLAN_OVERDUE.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.PAY_PLAN_OVERDUE));
                //type
                pushObject.put("type", new JSONArray());
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);
                //pushtime
                JSONObject pushTimeObject = new JSONObject();
                pushTimeObject.put("loop", 0);
                pushTimeObject.put("timeType", PushTimeTypeEnum.DELAYED.getCode());
                pushTimeObject.put("period", oneDay);
                pushTimeObject.put("time", 0);
                pushTimeObject.put("type", 1);

                JSONArray timeArray = new JSONArray();
                JSONObject timeObject1 = new JSONObject();
                timeObject1.put("id", 2);
                timeObject1.put("name",  I18nMessageUtil.getMessage(CommonConstant.DELAYED));
                timeArray.add(timeObject1);
                JSONObject timeObject2 = new JSONObject();
                timeObject2.put("id", 3);
                timeObject2.put("name", I18nMessageUtil.getMessage(CommonConstant.THE_DAY));
                timeArray.add(timeObject2);
                pushTimeObject.put("timeArray", timeArray);

                pushSetEntity.setPushTime(pushTimeObject.toJSONString());

            }
            pushSetEntity.setPushObject(pushObject.toJSONString());
        } else {
            pushSetEntity = pushSetList.get(0);
            if (Objects.equals(PushTypeEnum.PAY_PLAN_OVERDUE.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.PAY_PLAN_OVERDUE.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.PAY_PLAN_OVERDUE));
            }
        }
        return pushSetEntity;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, String attr, PushSetModel pushSetModel) {
        return null;
    }

    @Override
    public List<PushSetEntity> getPushSet(String corpid, List<String> attrList, PushSetModel pushSetModel, Long templateId) {
        return null;
    }

    @Override
    public JSONObject getTimeJson(JSONObject jsonObject) {
        return null;
    }
}
